package cn.edu.njuit.lesson9heros.springioc;

import cn.edu.njuit.lesson9heros.pojo.Team;
import cn.edu.njuit.lesson9heros.service.EquipmentService;
import cn.edu.njuit.lesson9heros.service.GameService;
import cn.edu.njuit.lesson9heros.service.TeamService;
import org.springframework.stereotype.Component;

@Component
public class SpringGameStarter {

    private final GameService gameService;
    private final TeamService teamService;
    private final EquipmentService equipmentService;

    public SpringGameStarter(GameService gameService, TeamService teamService, EquipmentService equipmentService) {
        this.gameService = gameService;
        this.teamService = teamService;
        this.equipmentService = equipmentService;
    }


    public void start(){
        Team blueTeam=teamService.getTeam(null);
        //安排装备
        blueTeam.getAdcHero().setEquipment(equipmentService.getHeroEquipment(blueTeam.getAdcHero()));
        blueTeam.getJungleHero().setEquipment(equipmentService.getHeroEquipment(blueTeam.getJungleHero()));
        blueTeam.getMidHero().setEquipment(equipmentService.getHeroEquipment(blueTeam.getMidHero()));
        blueTeam.getSupportHero().setEquipment(equipmentService.getHeroEquipment(blueTeam.getSupportHero()));
        blueTeam.getTopHero().setEquipment(equipmentService.getHeroEquipment(blueTeam.getTopHero()));

        Team redTeam=teamService.getTeam(blueTeam);
        //安排装备
        redTeam.getAdcHero().setEquipment(equipmentService.getHeroEquipment(redTeam.getAdcHero()));
        redTeam.getJungleHero().setEquipment(equipmentService.getHeroEquipment(redTeam.getJungleHero()));
        redTeam.getMidHero().setEquipment(equipmentService.getHeroEquipment(redTeam.getMidHero()));
        redTeam.getSupportHero().setEquipment(equipmentService.getHeroEquipment(redTeam.getSupportHero()));
        redTeam.getTopHero().setEquipment(equipmentService.getHeroEquipment(redTeam.getTopHero()));
        gameService.play(blueTeam,redTeam);
    }
}
